home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_portmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  1.6 KB  |  73 lines

  1. /*
  2.   decode_portmap.c
  3.  
  4.   RPC portmap.
  5.   
  6.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  7.  
  8.   $Id: decode_portmap.c,v 1.2 2000/05/16 21:27:53 dugsong Exp $
  9. */
  10.  
  11. #include <sys/types.h>
  12. #include <rpc/rpc.h>
  13. #include <rpc/pmap_prot.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <libnet.h>
  17. #include <nids.h>
  18. #include "rpc.h"
  19. #include "trigger.h"
  20. #include "decode.h"
  21.  
  22. int
  23. decode_portmap(u_char *buf, int len)
  24. {
  25.     struct rpc_msg msg;
  26.     struct pmap *pm, pmap;
  27.     struct xid_map *xm;
  28.     XDR xdrs;
  29.     int hdrlen;
  30.  
  31.     memset(&msg, 0, sizeof(msg));
  32.     
  33.     if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
  34.         return (0);
  35.     
  36.     if (msg.rm_direction == CALL &&
  37.         msg.rm_call.cb_prog == PMAPPROG &&
  38.         msg.rm_call.cb_proc == PMAPPROC_GETPORT) {
  39.         xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen, XDR_DECODE);
  40.         if (!xdr_pmap(&xdrs, &pmap)) {
  41.             xdr_destroy(&xdrs);
  42.             return (0);
  43.         }
  44.         xdr_destroy(&xdrs);
  45.  
  46.         if ((pm = (struct pmap *) malloc(sizeof(*pm))) == NULL)
  47.             return (0);
  48.         *pm = pmap;
  49.         
  50.         xid_map_enter(msg.rm_xid, PMAPPROG, (void *) pm);
  51.     }
  52.     else if (msg.rm_direction == REPLY &&
  53.          (xm = xid_map_find(msg.rm_xid)) != NULL) {
  54.         if (msg.rm_reply.rp_stat == MSG_ACCEPTED &&
  55.             msg.acpted_rply.ar_stat == SUCCESS &&
  56.             len - hdrlen == 4) {
  57.             pm = (struct pmap *) xm->data;
  58.             pm->pm_port = ntohl(*(u_long *)(buf + hdrlen));
  59.  
  60.             if (pm->pm_port) {
  61.                 /* XXX - any client-only RPC decodes? */
  62.                 trigger_rpc(pm->pm_prog, pm->pm_prot,
  63.                         pm->pm_port);
  64.                 trigger_rpc(pm->pm_prog, pm->pm_prot,
  65.                         0 - (int) pm->pm_port);
  66.             }
  67.         }
  68.         free(xm->data);
  69.         memset(xm, 0, sizeof(*xm));
  70.     }
  71.     return (0);
  72. }
  73.